package com.tan.androidtest.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.tan.androidtest.R;

import java.util.ArrayList;
import java.util.List;

/**
 * 联系人信息
 */

public class NormalAdapter extends BaseAdapter {

    private List<String> beans = new ArrayList<>();
    private Context mContext;

    public NormalAdapter(Context context) {
        this.mContext = context;
    }

    public void loadBean(List<String> beans) {
        this.beans = beans;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return beans != null ? beans.size() : 0;
    }

    @Override
    public Object getItem(int position) {
        return beans != null ? beans.get(position) : null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        String bean = (String) getItem(position);
        Holder holder;
        if (convertView == null) {
            holder = new Holder();
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_normal_list_layout, parent, false);
            holder.text1 = convertView.findViewById(R.id.tv_test);
            convertView.setTag(holder);
        } else {
            holder = (Holder) convertView.getTag();
        }
        if (bean != null) {
            holder.text1.setText(bean);
        }
        return convertView;
    }

    class Holder {
        TextView text1;
    }

}
